procedure dfs(x,p:longint);

var
  i: longint;
        
begin
w[x] := 1;
for i := 1 to n do begin
  if (a[x][i] = 1) and (w[i] = 1) and (i <> pr) then inc(cycle) else
  if (a[x][i] = 1) and (w[i] = 0) and (i <> pr) then dfs(i, x);
end;
w[x] := 2;
end;
